<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/1 0001
 * Time: 17:48
 */

namespace app\common\model;

use think\Model;
class Base extends Model
{
    protected $autoWriteTimestamp = true;
    /**新增
     * @param array $data
     * @return mixed
     */
    public function add($data){
        if(!is_array($data)){
            exception('传递数据不合法');
        }
        $this->allowField(true)->save($data);
        return $this->id;
    }
    /**
     * 获取列表的数据---通用方法
     * @param array $condition
     * @param int $from
     * @param int $size
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getLstByCondition($condition = [], $from = 0, $size = 5){
        $condition['status'] = [
            'neq',config('code.status_delete')
        ];
        $order = ['id' => 'desc'];
        $result = $this->where($condition)
            ->limit($from,$size)
            ->order($order)
            ->select();
//        echo $this->getLastSql();
        return $result;

    }

    /**
     * 根据条件来获取列表的数据总和---通用方法
     * @param array $condition
     * @return int|string
     */
    public function getLstCountByCondition($condition = []){
        $condition['status'] = [
            'neq',config('code.status_delete')
        ];
        return $this->where($condition)
            ->count();
    }

}